package com.hmys.api.service.impl;

import com.hmys.api.mapper.WebHouseCollectionMapper;
import com.hmys.api.model.WebHouseCollection;
import com.hmys.api.service.WebHouseCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by chen365 on 2018/03/29.
 */
@Service
public class WebHouseCollectionServiceImpl implements WebHouseCollectionService {
    @Autowired
    private WebHouseCollectionMapper webHouseCollectionMapper;


    @Override
    public int save(Long userId, Long houseId) {
        WebHouseCollection record = new WebHouseCollection();
        record.setUserId(userId);
        record.setHouseId(houseId);

        if (webHouseCollectionMapper.selectCountByBean(record) > 0) {
            return webHouseCollectionMapper.deleteByBean(record);
        } else {
            record.setStatus(true);
            record.setCreateTime(new Date());
            return webHouseCollectionMapper.insertSelective(record);
        }
    }

    @Override
    public List<Long> selectHouseIdsByUserId(Long userId) {
        return webHouseCollectionMapper.selectHouseIdsByUserId(userId);
    }
}
